#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置初始值
    ui->lcdNumber->display(10);
    //开启定时器
    _timerId = this->startTimer(1000);
}

Widget::~Widget()
{
    delete ui;
}

//定时器事件处理函数
void Widget::timerEvent(QTimerEvent *event)
{
    //获取触发定时器事件是哪一个定时器
    if(event->timerId() != this->_timerId)
    {
        return;
    }
    int value = ui->lcdNumber->intValue();
    if(value <= 0)
    {
        this->killTimer(this->_timerId);
        return;
    }
    ui->lcdNumber->display(value - 1);
}
